import java.util.Arrays;

public class Bubblesort {

    public static void Bubblesort1(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            boolean flg = false;
            for (int j = 0; j <array.length-1-i; j++) {
                if(array[j] > array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = true;
                }
            }
            if(flg == false) {
                return; //说明已经有序了
            }
        }
    }
    public static void main(String[] args) {
        int[] array ={1,12,15,3,8,6};
        System.out.println(Arrays.toString(array));
        Bubblesort1(array);
        System.out.println(Arrays.toString(array));
    }
}
